#include <iostream>
#include <cstring>
using namespace std;
class MyQueue
{
    int count = 0; //让计数器属于类内成员，好调用
    int num[500];  //队列
public:
    void push(int);
    int pop();
    int size();
};
void MyQueue::push(int x) //增加队列元素
{
    num[count++] = x;
}
int MyQueue::pop() //队列头元素出列
{
    if (count == 0) //无元素时
        return -1;
    int x = num[0];
    for (int i = 0; i < count - 1; i++)
        num[i] = num[i + 1];
    count--;
    return x;
}
int MyQueue::size() // count就是队列大小
{
    return count;
}
int main()
{
    int n, k;
    cin >> n;
    MyQueue text; //创建对象
    int num;
    for (int i = 0; i < n; i++)
    {
        cin >> k;
        switch (k) //用switch判断操作
        {
        case 1:
            cin >> num;
            text.push(num);
            break;
        case 2:
            num = text.pop();
            if (num == -1)
                cout << "Invalid" << endl;
            else
                cout << num << endl;
            break;
        case 3:
            cout << text.size() << endl;
        }
    }
}
